xen/grant-table: Simplify the update to the per-vCPU maptrack freelist
authorJulien Grall <jgrall@amazon.com>
Mon, 14 Jun 2021 10:08:30 +0000 (11:08 +0100)
committerJulien Grall <jgrall@amazon.com>
Mon, 14 Jun 2021 10:09:20 +0000 (11:09 +0100)
commit4f1858763b7b1aeb79fa7c818eca98c96943aa69
tree07f8c47718f10925765d392f407840d21049ec33
parent93031fbe9f4c341a2e7950a088025ea550291433
xen/grant-table: Simplify the update to the per-vCPU maptrack freelist

Since XSA-228 (commit 02cbeeb62075 "gnttab: split maptrack lock
to make it fulfill its purpose again"), v->maptrack_head,
v->maptrack_tail and the content of the freelist are accessed with
the lock v->maptrack_freelist_lock held.

Therefore it is not necessary to update the fields using cmpxchg()
and also read them atomically.

Note that there are two cases where v->maptrack_tail is accessed without
the lock. They both happen in get_maptrack_handle() when initializing
the free list of the current vCPU. Therefore there is no possible race.

The code is now reworked to remove any use of cmpxch() and read_atomic()
when accessing the fields v->maptrack_{head, tail} as wel as the
freelist.

Take the opportunity to add a comment on top of the lock definition
and explain what it protects.

Signed-off-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/common/grant_table.c
xen/include/xen/sched.h